home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10794 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  92 lines

  1. Path: nntpd.lkg.dec.com!usenet
  2. From: wells@lkg.dec.com (Phil Wells)
  3. Newsgroups: comp.lang.c++
  4. Subject: How to initialize a private member struct
  5. Date: Sun, 10 Mar 1996 16:10:12 GMT
  6. Organization: Digital Equipment Corporation
  7. Message-ID: <4hse0q$q1o@nntpd.lkg.dec.com>
  8. NNTP-Posting-Host: pwrkdhcp31.lkg.dec.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi,
  12.  
  13. I have a program that joins single bitmaps into a larger bitmap
  14. "sheet" and also creates a .c file to describe the sheet layout.  I
  15. broke up that base file into two pieces: the definition which I put in
  16. the class definition .h file and the data which I put in the .cpp
  17. file.
  18.  
  19. When processing the bitmap data, I use this data to create a loop
  20. which first creates a DirectDrawSurface object for each of the image
  21. groups and then copies that surface's bitmap data to the surface
  22. object.
  23.  
  24. Seems simple enough, but I immediatly got into problems because  I had
  25. created a static definition for the sBitmap object (see example below)
  26. and it was referencing private data members out of scope.
  27.  
  28. I experimented with various things including
  29.     - making the sBitmap object a friend of my class
  30.     - making the sBitmap object a static data member of my class
  31.     - making the sBitmap object a public data member and referencing it    
  32.       with &sBitmap::s1
  33.  
  34. Each of these had problems.  Eventually I got tired of trying things
  35. and moved the LPDIRECTDRAW object pointers out of the class and into
  36. the .C file as static variables.
  37.  
  38. I guess my basic question is how can I create class stuctures that
  39. contain pointers other members of the class at compile time?
  40.  
  41. Thanks
  42.  
  43. Phil
  44.  
  45. // in the class .h file 
  46. #define FRAMES_PER_ROW        8
  47. #define BITMAPFILE        "ships.bmp"
  48.  
  49. struct sBitmap
  50.     {
  51.     long RowSize;
  52.     int ImageCount;
  53.     int XFrameSize;
  54.     int YFrameSize;
  55.     struct sFrames
  56.     {
  57.     int StartFrame;
  58.     int Count;
  59.     LPDIRECTDRAWSURFACE *dds;
  60.     } FrameData[6];
  61.     };
  62.  
  63.  
  64. class x
  65. {
  66.     .
  67.     .
  68.     .
  69. private
  70.     LPDIRECTDRAWSURFACE    s1;
  71.     LPDIRECTDRAWSURFACE    s2;
  72.     LPDIRECTDRAWSURFACE    s3;
  73.     LPDIRECTDRAWSURFACE    s4;
  74.     LPDIRECTDRAWSURFACE    s5;
  75.     LPDIRECTDRAWSURFACE    s6;
  76. };
  77. -----
  78.  
  79. // in the class .cpp file
  80.  
  81. static struct sShipBitmap = 
  82.     {
  83.     720000, 47, 300, 300, 
  84.      0,  1, &s1    /* center */
  85.      1, 16, &s2    /* 360 loop */
  86.     17, 13, &s3    /* roll right */
  87.     30,  9, &s4     /* turn right 90 */
  88.     39,  8, &s5     /* turn left 90 */
  89.      0, 0};
  90.  
  91.  
  92.